﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hostal.Bussines.Entities;
using Hostal.Bussines.Logic;
using Hostal.Bussines.Logic.Service;
using Microsoft.Practices.Unity;

namespace Hostal.MVC.Controllers
{
    public class InsumoController : Controller
    {
        [Dependency]
        public IInsumoService InsumoService { set; get; }

        //
        // GET: /Insumo/

        public ActionResult Index()
        {
            var lista=InsumoService.GetAllFromInsumo();
            return View(lista);
        }

        [HttpPost]

        public ActionResult Index(string nombre = "")
        {
            var lista = InsumoService.GetFromInsumoByNombre(nombre);
            return View(lista);
        }

        public ActionResult Create()
        {
            var insumo = new Insumo();
            return View(insumo);
        }

        [HttpPost]
        public ActionResult Create(Insumo insumo)
        {
            InsumoService.AddInsumo(insumo);
            return RedirectToAction("Index");
        }

        public ActionResult Edit(Int32 id)
        {
            var insumo = InsumoService.GetFromInsumoById(id);
            return View(insumo);
        }

        [HttpPost]
        public ActionResult Edit(Insumo insumo)
        {
            InsumoService.UpdateInsumo(insumo);
            return RedirectToAction("Index");
        }

        public ActionResult Delete(Int32 id)
        {
            InsumoService.RemoveInsumo(id);
            return RedirectToAction("Index");
        }
    }
}
